package com.isoft.airportsystem.controller.change;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isoft.airportsystem.common.change.Result;
import com.isoft.airportsystem.entity.change.NotificationRecord;
import com.isoft.airportsystem.entity.change.NotificationSubscription;
import com.isoft.airportsystem.entity.dao.NotificationSubscriptionDTO;
import com.isoft.airportsystem.entity.dao.PageQuery;
import com.isoft.airportsystem.service.change.NotificationService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/notifications")  // 通知管理
public class NotificationController {

    private final NotificationService notificationService;

    public NotificationController(NotificationService notificationService) {
        this.notificationService = notificationService;
    }

    @PostMapping("/subscriptions")   // 订阅变更通知
    public Result<NotificationSubscription> subscribe(
            @RequestBody NotificationSubscriptionDTO dto) {
        return notificationService.subscribeFlightChange(dto);
    }

    @DeleteMapping("/subscriptions/{id}")   // 取消订阅变更通知
    public Result<Void> unsubscribe(@PathVariable String id) {
        return notificationService.unsubscribe(id);
    }

    @GetMapping("/records")    // 获取通知记录
    public Page<NotificationRecord> getRecords(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size,
            @RequestParam(required = false) String flightId,
            @RequestParam(required = false) String status) {
        PageQuery query = new PageQuery(page, size);
        return notificationService.getNotificationRecords(query, flightId, status);
    }
}